package com.huaqiang.test.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import lombok.extern.slf4j.Slf4j;
import com.huaqiang.baseline.base.baseBean.BaseController;
import com.huaqiang.baseline.base.pojo.vo.ResponseResult;
import com.huaqiang.baseline.base.exception.BusinessException;

import java.util.List;

import com.huaqiang.test.pojo.vo.AlertHandleVo;
import com.huaqiang.test.pojo.entity.AlertHandle;
import com.huaqiang.test.pojo.query.AlertHandleQuery;
import com.huaqiang.test.service.AlertHandleService;

import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 告警处理表接口
 *
 * @author crelle
 * @since 2025-03-20 04:48:55
 */
@RestController
@RequestMapping("/test/alert-handle")
@Slf4j
public class AlertHandleController implements BaseController<AlertHandleVo, AlertHandle, AlertHandleQuery> {

    @Autowired
    private AlertHandleService alerthandleService;

    /**
     * 创建AlertHandle
     *
     * @param object
     * @return
     */
    @Override
    @RequestMapping(value = "/create", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<AlertHandle> create(AlertHandle object) {
        ResponseResult<AlertHandle> responseResult = new ResponseResult<>();
        try {
            alerthandleService.create(object);
            responseResult.setData(object);
        } catch (Exception e) {
            log.error("创建AlertHandle失败,e={}", e);
            throw new BusinessException("创建AlertHandle失败");
        }
        return responseResult;
    }

    /**
     * 批量创建AlertHandle
     *
     * @param objects
     * @return
     */
    @Override
    @RequestMapping(value = "/creates", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<List<AlertHandle>> creates(List<AlertHandle> objects) {
        ResponseResult<List<AlertHandle>> responseResult = new ResponseResult<>();
        try {
            alerthandleService.create(objects);
            responseResult.setData(objects);
        } catch (Exception e) {
            log.error("批量创建AlertHandle失败,e={}", e);
            throw new BusinessException("批量创建AlertHandle失败");
        }
        return responseResult;
    }

    /**
     * 删除AlertHandle
     *
     * @param id
     * @return
     */
    @Override
    @RequestMapping(value = "/deleteById/{id}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<String> deleteById(@PathVariable("id") String id) {
        ResponseResult<String> responseResult = new ResponseResult<>();
        try {
            alerthandleService.deleteById(id);
        } catch (Exception e) {
            log.error("删除AlertHandle失败,e={}", e);
            throw new BusinessException("删除AlertHandle失败");
        }
        return responseResult;
    }

    /**
     * 批量删除AlertHandle
     *
     * @param ids
     * @return
     */
    @Override
    @RequestMapping(value = "/deleteByIds", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<String> deleteByIds(@RequestBody List<String> ids) {
        ResponseResult<String> responseResult = new ResponseResult<>();
        try {
            alerthandleService.deleteByIds(ids);
        } catch (Exception e) {
            log.error("批量删除AlertHandle失败,e={}", e);
            throw new BusinessException("批量删除AlertHandle失败");
        }
        return responseResult;
    }

    /**
     * 更新AlertHandle
     *
     * @param object
     * @return
     */
    @Override
    @RequestMapping(value = "/updateById", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<String> updateById(@RequestBody AlertHandle object) {
        ResponseResult<String> responseResult = new ResponseResult<>();
        try {
            alerthandleService.update(object);
        } catch (Exception e) {
            log.error("更新AlertHandle失败,e={}", e);
            throw new BusinessException("更新AlertHandle失败");
        }
        return responseResult;
    }

    /**
     * 批量更新AlertHandle
     *
     * @param objects
     * @return
     */
    @Override
    @RequestMapping(value = "/updateByIds", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<String> updateByIds(@RequestBody List<AlertHandle> objects) {
        ResponseResult<String> responseResult = new ResponseResult<>();
        try {
            alerthandleService.updates(objects);
        } catch (Exception e) {
            log.error("批量更新AlertHandle失败,e={}", e);
            throw new BusinessException("批量更新AlertHandle失败");
        }
        return responseResult;
    }


    /**
     * 自动分页查询AlertHandle
     *
     * @param pageBean
     * @return
     */
    @Override
    @RequestMapping(value = "/page", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<Page<AlertHandle>> page(@RequestBody Page<AlertHandle> pageBean) {
        ResponseResult<Page<AlertHandle>> responseResult = new ResponseResult<>();
        try {
            Page<AlertHandle> page = alerthandleService.pageByCondition(pageBean);
            responseResult.setData(page);
        } catch (Exception e) {
            log.error("自动分页查询AlertHandle失败,e={}", e);
            throw new BusinessException("自动分页查询AlertHandle失败");
        }
        return responseResult;
    }

    /**
     * 手动分页查询AlertHandle
     *
     * @param pageBean
     * @return
     */
    @Override
    @RequestMapping(value = "/manualPage", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<Page<AlertHandleVo>> manualPage(@RequestBody Page<AlertHandleQuery> pageBean) {
        ResponseResult<Page<AlertHandleVo>> responseResult = new ResponseResult<>();
        try {
            Page<AlertHandleVo> AlertHandleVoPage = alerthandleService.manualPage(pageBean);
            responseResult.setData(AlertHandleVoPage);
        } catch (Exception e) {
            log.error("手动分页查询AlertHandle失败,e={}", e);
            throw new BusinessException("手动分页查询AlertHandle失败");
        }
        return responseResult;
    }

    /**
     * 根据id查询AlertHandle详情
     *
     * @param id
     * @return
     */
    @Override
    @RequestMapping(value = "/queryById/{id}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<AlertHandle> queryById(@PathVariable("id") String id) {
        ResponseResult<AlertHandle> responseResult = new ResponseResult<>();
        try {
            AlertHandle AlertHandle = alerthandleService.queryById(id);
        responseResult.setData(AlertHandle);
        } catch (Exception e) {
            log.error("根据id查询AlertHandle详情失败,e={}", e);
            throw new BusinessException("根据id查询AlertHandle详情失败");
        }
        return responseResult;
    }

    /**
     * 根据id批量查询AlertHandle详情
     *
     * @param ids
     * @return
     */
    @Override
    @RequestMapping(value = "/queryByIds", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<List<AlertHandle>> queryByIds(@RequestBody List<String> ids) {
        ResponseResult<List<AlertHandle>> responseResult = new ResponseResult<>();
        try {
            List<AlertHandle> AlertHandle = alerthandleService.queryByIds(ids);
            responseResult.setData(AlertHandle);
        } catch (Exception e) {
            log.error("根据id批量查询AlertHandle详情失败,e={}", e);
            throw new BusinessException("根据id批量查询AlertHandle详情失败");
        }
        return responseResult;
    }

    /**
     * 查询所有AlertHandle
     *
     * @return
     */
    @Override
    @RequestMapping(value = "/queryAll", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseResult<List<AlertHandle>> queryAll() {
        ResponseResult<List<AlertHandle>> responseResult = new ResponseResult<>();
        try {
            List<AlertHandle> AlertHandle = alerthandleService.queryAll();
            responseResult.setData(AlertHandle);
        } catch (Exception e) {
            log.error("查询所有AlertHandle失败,e={}", e);
            throw new BusinessException("查询所有AlertHandle失败");
        }
        return responseResult;
    }
}
